<template>
    <el-card>
      <el-table
          :data="tableData"
          border
          style="width: 100%">
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column
            prop="hariName"
            label="项目"
            width="150">
        </el-table-column>
        <el-table-column
            label="展示"
            width="180">
          <template slot-scope="scope">
            <el-image :src="scope.row.hairImg"></el-image>
          </template>
        </el-table-column>
        <el-table-column
            prop="barberName"
            label="教练"
            width="150">
        </el-table-column>
        <el-table-column
            prop="orderDate"
            label="预约日期"
            width="150">
        </el-table-column>
        <el-table-column
            prop="price"
            label="价格"
            width="150">
        </el-table-column>
        <el-table-column
            label="操作"
           >
          <template slot-scope="scope">
            <el-button @click="okClick(scope.row)" type="text" size="small">下单</el-button>
            <el-button @click="delClick(scope.row)" type="text" style="color:red;" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
</template>

<script>
export default {
  name: "cart",
  data(){
    return{
      phone:this.$store.getters.get_user.phone,
      tableData: []
    }
  },
  mounted() {
    this.cartList();
  },
  methods:{
     async cartList(){
      const userId= this.$store.getters.get_user.id
      const res= await this.$axios.get('api/cart/findCart/'+userId)
       this.tableData=res.data.content
       console.log(res)
    },
    async okClick(e){
       console.log('下单')
      const res= await this.$axios.post('api/order/addOrder',[e.cartId])
       // console.log(e)
      if (res.data.success==true){
        this.$message({
          message: '下单成功',
          type: 'success',
          offset: 80
        })
      }
      // console.log(res)
      this.cartList();
    },
    async  delClick(e){
      console.log('删除')
      const res= await this.$axios.delete('api/cart/delCart/'+e.cartId)
      if (res.data.success==true){
        this.$message({
          message: '删除成功',
          type: 'success',
          offset: 80
        })
      }
      this.cartList();
      console.log(e)
    }
  }
}
</script>

<style scoped>

</style>